package cn.bytecollege.admin.service;

import cn.bytecollege.admin.dao.OrderDao;
import cn.bytecollege.common.entity.Orders;
import cn.bytecollege.common.entity.Page;

import java.sql.SQLException;
import java.util.List;


/**
 * @author NJK
 */
public class OrderService {
    private OrderDao orderDao = null;
    public OrderService(){
        orderDao = new OrderDao();
    }
    /**
     * 根据支付状态分页查询订单
     * @author NJK
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Page<Orders> findOrderByPage(int pageIndex, int pageSize, int payflag){
        List<Orders> list =orderDao.findOrderByPage(pageIndex,pageSize,payflag);
        //根据支付状态查询总条数
        int count = orderDao.countByPayFlag(payflag);
        //分装Page对象
        Page<Orders> page = new Page<>();
        page.setCurrentIndex(pageIndex);
        page.setList(list);
        page.setTotal(count);
        page.setPageSize(pageSize);
        page.setTotalPage(count);
        page.setPageIndex();

        return page;
    }

    /**
     * 根据订单号删除订单
     * @author NJK
     * @param orderNumber
     * @return
     */
    public int deleteByOrderNumber(String orderNumber){
        return orderDao.deleteByOrderNumber(orderNumber);
    }
    /**
     * 修改订单的支付状态
     * @author NJK
     * @param orders
     * @return
     */
    public int updatePayFlag(Orders orders) {
        return orderDao.updatePayFlag(orders);
    }
    /**
     * 在订单表中添加数据
     * @author zhy
     * @param orders
     * @return
     */
    public int save(Orders orders) {
        return orderDao.save(orders);
    }
}
